package org.fujene.sandbox;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.fujene.communicate.local.LocalPeerSystem;
import org.fujene.structure.Enumerates;
import org.fujene.structure.IndexQueue;

//public class TestSearch extends TestCase {
public class TestSearchLocal {
/*	public static void testMain() throws IOException, InterruptedException {
		// クライアント
		SimpleClient client = new SimpleClient();
		// サーバ
		// PeerSystem peer = new PeerSystem();

		new Executor() {
			@Override
			public void execute(Runnable runnable) {
				new Thread(runnable).start();
			}
		}.execute(client);
		new PeerSystem().testMain(null);
	}*/

//	public static void testSearch() throws InterruptedException, IOException {
	public static void main(String[] args) throws Exception {
		LocalPeerSystem peer = new LocalPeerSystem();
		
		peer.initialize();
		
		peer.testMain(null);
		
		BufferedReader ir = new BufferedReader(new InputStreamReader(System.in));
		String line;
		
		while(true){
			System.out.print("追加(i) / 検索(s) / 終了(q) -> ");
			line = ir.readLine();
			
			if(line.equals("i")){
				// インデックス
				System.out.print("語句を入力してください -> ");
				line = ir.readLine();
				IndexQueue inq = new IndexQueue(Enumerates.INDEX, line, System.currentTimeMillis());
				peer.setNewIndex(inq);
//				indexqueue.put(inq);
			}else if(line.equals("s")){
				// 検索
				System.out.print("クエリを入力してください -> ");
				line = ir.readLine();
				IndexQueue seq = new IndexQueue(Enumerates.SEARCH, line, System.currentTimeMillis());
				peer.setNewSearch(seq);
//				searchqueue.put(seq);
			}else if(line.equals("q")){
				peer.setStopper(true);
				break;
			}else{
				
			}
			
			Thread.sleep(200);
		}
		
		System.out.println("Main thread ends.");
	}
}